//
//  TestRun.m
//  WiteBox
//
//  Created by John Blanco on 6/27/09.
//  Copyright 2009 Effective UI. All rights reserved.
//

#import "TestRun.h"
#import "AssertionException.h"

@implementation TestRun

@synthesize isTestComplete;
@synthesize isPassingTest;
@synthesize exception;
@synthesize duration;

- (id)initWithSelector:(SEL)aTestMethod {
	self = [super init];
	
	if (self) {
		testMethod = aTestMethod;
		isTestComplete = NO;
		isPassingTest = NO;
	}
	
	return self;
}

- (void)dealloc {
	[exception release];
	[super dealloc];
}

#pragma mark -

- (SEL)testMethod {
	return testMethod;
}

- (NSString *)testMethodName {
	return NSStringFromSelector(testMethod);
}

- (NSString *)exceptionFilename {
	if ([exception isKindOfClass:[AssertionException class]]) {
		return ((AssertionException *)exception).filename;
	}
	
	return nil;
}

- (NSInteger)exceptionLineNumber {
	if ([exception isKindOfClass:[AssertionException class]]) {
		return ((AssertionException *)exception).lineNumber;
	}
	
	return -1;
}

- (NSString *)exceptionExpectedValue {
	if ([exception isKindOfClass:[AssertionException class]]) {
		return ((AssertionException *)exception).expectedValue;
	}
	
	return @"";
}

- (NSString *)exceptionActualValue {
	if ([exception isKindOfClass:[AssertionException class]]) {
		return ((AssertionException *)exception).actualValue;
	} else if ([exception isKindOfClass:[NSException class]]) {
		return [exception description];
	}
	
	return @"";
}

@end
